<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>

<?php

   require_once "Controller.php";
   require_once "Home/Model/IndexModel.php";
   class IndexController extends Controller{
       function __construct(){
        parent::__construct();
        $this->mod=new IndexModel();
       }
       //首页
       public function index(){
        $this->display();

       }
       //列表页
       public function menu(){

      $fooddata=$this->mod->getFoodList();

      //$userdata2=$this->mod->getUserList2();

      $this -> assign("food",$fooddata);

      //$this -> assign("users2",$userdata2);


      $this -> display();
       }
       //内容页
       public function start(){
        $this->display();
      }
        public function adminLog(){
          $this->display();
        }
        public function userReg(){
          $this->display();
        }
        public function login(){
          $this->display();
        }
        public function adduser()
        {
          $result=$this->mod->addUserInfo($_POST);
          if($result == true)
          {
            echo "注册用户成功！";
            echo '<a href="index.php?c=index&m=start">如果没有跳转，请点这里跳转</a>';
            header("refresh:3;url='index.php?c=index&m=start'");
          }
          else
          {
            //header("location:index.php?c=index&m=listusers");
            echo '添加失败！';
          }
          
        }

        public function doLogin()
        {
          $result = $this -> mod ->doLoginInfo($_POST);
          if($result == true)
          {
            session_start();
            $_SESSION["user"]=$_POST["name"];
            header("location:index.php?c=index&m=start");
          }
          else
          {
            echo "登陆失败！请检查用户名密码是否输入错误！";
            //header("location:index.php?c=index&m=login");
            header("refresh:3;url='index.php?c=index&m=login'");
          }
        }
         public function doAdminLogin()
        {
          $result = $this -> mod ->doAdminLoginInfo($_POST);
          if($result == true)
          {
            session_start();
            $_SESSION["adminUser"]=$_POST["adminUser"];
            header("location:Admin/index");
          }
          else
          {
            echo "登陆失败！请检查管理员用户名密码是否输入错误！";
            //header("location:index.php?c=index&m=login");
            header("refresh:3;url='index.php?c=index&m=adminLog'");
          }
        }

        public function logout()
        {
          session_start();
          session_destroy();
          header("location:index.php?c=index&m=start");
        }

        public function userEditForm()
        {
          $data = $this -> mod -> getUserByName();
          $this -> assign("user",$data);
          $this -> display();
        }
        public function orderlist()
        {
          $data = $this -> mod -> getOrderByUID();
          $this -> assign("orders",$data);
          $this -> display();


        }
        public function updateuser()
        {
          $result = $this -> mod -> updateUserInfo($_POST);
          if($result == true)
          {
            echo '修改成功<br/>';
            session_start();
            session_destroy();
            header("location:index.php?c=index&m=start");
          }
          else
          {
            //header("location:index.php?c=user&m=listusers");
            echo '修改失败';
          }
        }

        public function addorderRtlist()
        {
          $result=$this->mod->addOrderInfo($_POST);
          if($result == true)
          {
            $data = $this -> mod -> getOrderByUID();
            $this -> assign("orders",$data);
            $this -> display();
            //echo '添加成功<br/>';
           // echo '<a href="index.php?c=index&m=orderlist">如果没有跳转，请点这里跳转</a>';
          }
          else
          { 
            echo '添加失败！';
            //header("location:index.php?c=index&m=start");
           
          }
        }

   }//class Usercontroller end


?>
</body>
</html>

